home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
msflex1a
/
frmflexn.frm
next >
Wrap
Text File
|
1999-09-20
|
6KB
|
207 lines
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form frmFlexNavigate
Caption = "Ascii Code Table"
ClientHeight = 1635
ClientLeft = 60
ClientTop = 345
ClientWidth = 3960
KeyPreview = -1 'True
LinkTopic = "Form1"
ScaleHeight = 1635
ScaleWidth = 3960
StartUpPosition = 2 'CenterScreen
Begin VB.TextBox tabSimm
Height = 285
Left = 120
TabIndex = 1
Text = "Text1"
Top = 1680
Width = 855
End
Begin MSFlexGridLib.MSFlexGrid grd
Height = 1455
Left = 120
TabIndex = 0
Top = 120
Width = 3735
_ExtentX = 6588
_ExtentY = 2566
_Version = 65541
FixedCols = 0
FocusRect = 2
End
End
Attribute VB_Name = "frmFlexNavigate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'Program Documentation:
'
'Written by: Daniel L. Botkin
'Date: September 16, 1999
'Written in: Visual Basic 5.0 (SP3)
'
'What It Does:
' Allows user to use the Tab and Shift Tab keys to
' Navigate between cells in MSFlexGrid.
'
'Purpose:
' This code was written to show a very simplictic way
' of using the tab key for navigation between cells
' in MSFlexGrid. It was written to show the basic
' concept and nothing else. Please remember that the
' more code you write to manipulate MSFlexGrid the
' more this code will have to be modified.
'
'Why:
' To this present date I have not been able to find a
' way to trap the tab key. Since I use MSFlexGrid in
' alot of programs I write, I needed a way to navigate
' between cells in the grid with the Tab key. This is
' what I came up with. If there is a better way, such
' as through API calls, I would be interested in
' seeing it. Since I couldn't beat it I joined it.
'
'Experianced Programmers:
' This documentation was written for beginner
' programmers. If you are experianced skip the
' rest and just look at the code, it's not very
' difficult to figure out.
'
'Whats Needed:
' 1. A Form, MSFlexGrid, and Textbox.
' 2. The Form's KeyPreview property must be set
' to True.
' 3. The TabStop properties for all controls except
' for MSFlexGrid and Textbox should be set
' to false.
' 4. The MSFlexGrid TabIndex Property should be set
' to 0.
' 5. Navigation code should be put in the
' Textbox_GotFocus event.
' 6. The Textbox Visible property must be set to True.
' If you do not want to see it, place it off the
' visible portion of the form.
'
'How It Works:
' The program will start with focus set to the
' MSFlexGrid.
'
' When the tab key is pressed the focus
' is shifted to the Textbox. This will in turn invoke
' the Textbox_GotFocus Event. The Not ShiftPressed
' Navigation code is performed and focus is sent
' back to MSFlexGrid.
'
' When the Shift is pressed the Form_KeyDown Event is
' triggered, setting the ShiftPressed flag to true.
' Then when the Tab is pressed the focus is sent to
' the Textbox and the Textbox_Gotfocus Event is
' triggered. The ShiftPressed code is performed and
' focus is sent back to MSFlexGrid.
'
' When the Shift is released the Form_KeyUp Event is
' triggered, setting the ShiftPressed flag to False.
' Ready for next set of keys to be pressed.
Public ShiftPressed As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'If the Shift key is pressed, set Public variable
'ShiftPressed = True. This flag set to true tells
'the program the shift key is being pressed.
Select Case Shift
Case 1 'Shift Key
ShiftPressed = True
Case Else
'Unload form when Escape is pressed
'Has nothing to do with navigation, I am just
'lazy.
If KeyCode = 27 Then Unload frmFlexNavigate
End Select
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
'When the Shift Key is up set the ShiftPressed
'variable equal to false.
If Shift = 0 Then ShiftPressed = False
End Sub
Private Sub Form_Load()
Dim i As Integer
'Setup MSFlexGrid and assign data.
With grd
.Rows = 1
.FormatString = "^Ascii Code|^Alpha Character"
.ColWidth(0) = .Width / 2 - 50
.ColWidth(1) = .Width / 2 - 50
For i = 65 To 68
.AddItem i & vbTab & Chr$(i)
Next i
End With
End Sub
Private Sub grd_Click()
End Sub
Private Sub tabSimm_GotFocus()
'This is where you put your desired navigation code
'for Shift Tab and Tab respectfully.
With grd
'Shift is being pressed.
If ShiftPressed Then
If .Col = 1 Then
.Col = 0
ElseIf .Row = 1 Then
.Col = 1
.Row = .Rows - 1
Else
.Col = 1
.Row = .Row - 1
End If
End If
'Shift is not being pressed.
If Not ShiftPressed Then
If .Col = 0 Then
.Col = 1
ElseIf .Row = .Rows - 1 Then
.Col = 0
.Row = 1
Else
.Col = 0
.Row = .Row + 1
End If
End If
.SetFocus 'Set focus back to MSFlexGrid
End With
End Sub